package com.openbravo.pos.ticket;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.SerializableRead;
import com.openbravo.data.loader.SerializableWrite;
import com.openbravo.format.Formats;
import com.openbravo.pos.util.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.Properties;

public class TicketLineInfo
  implements SerializableWrite, SerializableRead, Serializable
{
  private static final long serialVersionUID = 6608012948284450199L;
  private String m_sTicket;
  private int m_iLine;
  private double multiply;
  private double price;
  private TaxInfo tax;
  private Properties attributes;
  private String productid;
  private String attsetinstid;

  public TicketLineInfo(String paramString, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo, Properties paramProperties)
  {
    init(paramString, null, paramDouble1, paramDouble2, paramTaxInfo, paramProperties);
  }

  public TicketLineInfo(String paramString, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo)
  {
    init(paramString, null, paramDouble1, paramDouble2, paramTaxInfo, new Properties());
  }

  public TicketLineInfo(String paramString1, String paramString2, String paramString3, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo)
  {
    Properties localProperties = new Properties();
    localProperties.setProperty("product.name", paramString2);
    localProperties.setProperty("product.taxcategoryid", paramString3);
    init(paramString1, null, paramDouble1, paramDouble2, paramTaxInfo, localProperties);
  }

  public TicketLineInfo(String paramString1, String paramString2, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo)
  {
    Properties localProperties = new Properties();
    localProperties.setProperty("product.name", paramString1);
    localProperties.setProperty("product.taxcategoryid", paramString2);
    init(null, null, paramDouble1, paramDouble2, paramTaxInfo, localProperties);
  }

  public TicketLineInfo()
  {
    init(null, null, 0.0D, 0.0D, null, new Properties());
  }

  public TicketLineInfo(ProductInfoExt paramProductInfoExt, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo, Properties paramProperties)
  {
    String str;
    if (paramProductInfoExt == null)
    {
      str = null;
    }
    else
    {
      str = paramProductInfoExt.getID();
      paramProperties.setProperty("product.name", paramProductInfoExt.getName());
      paramProperties.setProperty("product.com", paramProductInfoExt.isCom() ? "true" : "false");
      if (paramProductInfoExt.getAttributeSetID() != null)
        paramProperties.setProperty("product.attsetid", paramProductInfoExt.getAttributeSetID());
      paramProperties.setProperty("product.taxcategoryid", paramProductInfoExt.getTaxCategoryID());
      if (paramProductInfoExt.getCategoryID() != null)
        paramProperties.setProperty("product.categoryid", paramProductInfoExt.getCategoryID());
    }
    init(str, null, paramDouble1, paramDouble2, paramTaxInfo, paramProperties);
  }

  public TicketLineInfo(ProductInfoExt paramProductInfoExt, double paramDouble, TaxInfo paramTaxInfo, Properties paramProperties)
  {
    this(paramProductInfoExt, 1.0D, paramDouble, paramTaxInfo, paramProperties);
  }

  public TicketLineInfo(TicketLineInfo paramTicketLineInfo)
  {
    init(paramTicketLineInfo.productid, paramTicketLineInfo.attsetinstid, paramTicketLineInfo.multiply, paramTicketLineInfo.price, paramTicketLineInfo.tax, (Properties)paramTicketLineInfo.attributes.clone());
  }

  private void init(String paramString1, String paramString2, double paramDouble1, double paramDouble2, TaxInfo paramTaxInfo, Properties paramProperties)
  {
    this.productid = paramString1;
    this.attsetinstid = paramString2;
    this.multiply = paramDouble1;
    this.price = paramDouble2;
    this.tax = paramTaxInfo;
    this.attributes = paramProperties;
    this.m_sTicket = null;
    this.m_iLine = -1;
  }

  void setTicket(String paramString, int paramInt)
  {
    this.m_sTicket = paramString;
    this.m_iLine = paramInt;
  }

  public void writeValues(DataWrite paramDataWrite)
    throws BasicException
  {
    paramDataWrite.setString(1, this.m_sTicket);
    paramDataWrite.setInt(2, new Integer(this.m_iLine));
    paramDataWrite.setString(3, this.productid);
    paramDataWrite.setString(4, this.attsetinstid);
    paramDataWrite.setDouble(5, new Double(this.multiply));
    paramDataWrite.setDouble(6, new Double(this.price));
    paramDataWrite.setString(7, this.tax.getId());
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      this.attributes.storeToXML(localByteArrayOutputStream, "Openbravo POS", "UTF-8");
      paramDataWrite.setBytes(8, localByteArrayOutputStream.toByteArray());
    }
    catch (IOException localIOException)
    {
      paramDataWrite.setBytes(8, null);
    }
  }

  public void readValues(DataRead paramDataRead)
    throws BasicException
  {
    this.m_sTicket = paramDataRead.getString(1);
    this.m_iLine = paramDataRead.getInt(2).intValue();
    this.productid = paramDataRead.getString(3);
    this.attsetinstid = paramDataRead.getString(4);
    this.multiply = paramDataRead.getDouble(5).doubleValue();
    this.price = paramDataRead.getDouble(6).doubleValue();
    this.tax = new TaxInfo(paramDataRead.getString(7), paramDataRead.getString(8), paramDataRead.getString(9), paramDataRead.getTimestamp(10), paramDataRead.getString(11), paramDataRead.getString(12), paramDataRead.getDouble(13).doubleValue(), paramDataRead.getBoolean(14).booleanValue(), paramDataRead.getInt(15));
    this.attributes = new Properties();
    try
    {
      byte[] arrayOfByte = paramDataRead.getBytes(16);
      if (arrayOfByte != null)
        this.attributes.loadFromXML(new ByteArrayInputStream(arrayOfByte));
    }
    catch (IOException localIOException)
    {
    }
  }

  public TicketLineInfo copyTicketLine()
  {
    TicketLineInfo localTicketLineInfo = new TicketLineInfo();
    localTicketLineInfo.productid = this.productid;
    localTicketLineInfo.attsetinstid = this.attsetinstid;
    localTicketLineInfo.multiply = this.multiply;
    localTicketLineInfo.price = this.price;
    localTicketLineInfo.tax = this.tax;
    localTicketLineInfo.attributes = ((Properties)this.attributes.clone());
    return localTicketLineInfo;
  }

  public int getTicketLine()
  {
    return this.m_iLine;
  }

  public String getProductID()
  {
    return this.productid;
  }

  public String getProductName()
  {
    return this.attributes.getProperty("product.name");
  }

  public String getProductAttSetId()
  {
    return this.attributes.getProperty("product.attsetid");
  }

  public String getProductAttSetInstDesc()
  {
    return this.attributes.getProperty("product.attsetdesc", "");
  }

  public void setProductAttSetInstDesc(String paramString)
  {
    if (paramString == null)
      this.attributes.remove(paramString);
    else
      this.attributes.setProperty("product.attsetdesc", paramString);
  }

  public String getProductAttSetInstId()
  {
    return this.attsetinstid;
  }

  public void setProductAttSetInstId(String paramString)
  {
    this.attsetinstid = paramString;
  }

  public boolean isProductCom()
  {
    return "true".equals(this.attributes.getProperty("product.com"));
  }

  public String getProductTaxCategoryID()
  {
    return this.attributes.getProperty("product.taxcategoryid");
  }

  public String getProductCategoryID()
  {
    return this.attributes.getProperty("product.categoryid");
  }

  public double getMultiply()
  {
    return this.multiply;
  }

  public void setMultiply(double paramDouble)
  {
    this.multiply = paramDouble;
  }

  public double getPrice()
  {
    return this.price;
  }

  public void setPrice(double paramDouble)
  {
    this.price = paramDouble;
  }

  public double getPriceTax()
  {
    return this.price * (1.0D + getTaxRate());
  }

  public void setPriceTax(double paramDouble)
  {
    this.price = (paramDouble / (1.0D + getTaxRate()));
  }

  public TaxInfo getTaxInfo()
  {
    return this.tax;
  }

  public void setTaxInfo(TaxInfo paramTaxInfo)
  {
    this.tax = paramTaxInfo;
  }

  public String getProperty(String paramString)
  {
    return this.attributes.getProperty(paramString);
  }

  public String getProperty(String paramString1, String paramString2)
  {
    return this.attributes.getProperty(paramString1, paramString2);
  }

  public void setProperty(String paramString1, String paramString2)
  {
    this.attributes.setProperty(paramString1, paramString2);
  }

  public Properties getProperties()
  {
    return this.attributes;
  }

  public double getTaxRate()
  {
    return this.tax == null ? 0.0D : this.tax.getRate();
  }

  public double getSubValue()
  {
    return this.price * this.multiply;
  }

  public double getTax()
  {
    return this.price * this.multiply * getTaxRate();
  }

  public double getValue()
  {
    return this.price * this.multiply * (1.0D + getTaxRate());
  }

  public String printName()
  {
    return StringUtils.encodeXML(this.attributes.getProperty("product.name"));
  }

  public String printMultiply()
  {
    return Formats.DOUBLE.formatValue(Double.valueOf(this.multiply));
  }

  public String printPrice()
  {
    return Formats.CURRENCY.formatValue(Double.valueOf(getPrice()));
  }

  public String printPriceTax()
  {
    return Formats.CURRENCY.formatValue(Double.valueOf(getPriceTax()));
  }

  public String printTax()
  {
    return Formats.CURRENCY.formatValue(Double.valueOf(getTax()));
  }

  public String printTaxRate()
  {
    return Formats.PERCENT.formatValue(Double.valueOf(getTaxRate()));
  }

  public String printSubValue()
  {
    return Formats.CURRENCY.formatValue(Double.valueOf(getSubValue()));
  }

  public String printValue()
  {
    return Formats.CURRENCY.formatValue(Double.valueOf(getValue()));
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.ticket.TicketLineInfo
 * JD-Core Version:    0.6.0
 */